package com.grm.demo.countdowlatch;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class MyCountDownLatch {
    private CountDownLatch latch;

    public MyCountDownLatch(CountDownLatch latch) {
        this.latch = latch;
    }

    // 执行任务
    public void exec() {
        try {
            System.out.println(Thread.currentThread().getName() + " execute task. ");
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + " finished task. ");
        } finally {
            latch.countDown();
        }
    }
}
